package com.design.observe;

import java.util.ArrayList;
import java.util.List;

public class ObjectFor3D implements Subject{


    List<Observer>observers=new ArrayList<>();
    String msg;

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        if(observers.contains(observer)){
               observers.remove(observer);
        }
    }

    @Override
    public void notifyObservers() {
        observers.stream().parallel().forEach(observer->{
            observer.update(msg);
        });
    }

    public void setMsg(String msg) {
        this.msg = msg;
        notifyObservers();
    }
}
